using System.Collections.Generic;
using UnityEngine;

namespace Voodoo.Meta.RVModules
{
	public class KeyArea : MonoBehaviour
	{
		public KeyVisual keyPrefab;

		private List<KeyVisual> keys = new List<KeyVisual>();

		public void SetKeys(int numberOfKey)
		{
			for (int i = 0; i < keys.Count; i++)
			{
				if (numberOfKey > 0)
				{
					if (keys[i].CanBeEnable())
					{
						numberOfKey--;
					}
					continue;
				}
				return;
			}
			for (int num = numberOfKey - keys.Count; num > 0; num--)
			{
				KeyVisual keyVisual = Object.Instantiate(keyPrefab, base.transform);
				keys.Add(keyVisual);
				keyVisual.Enable();
			}
		}

		public bool UseAKey()
		{
			if (!IsAKeyAvailable())
			{
				return false;
			}
			for (int i = 0; i < keys.Count; i++)
			{
				if (keys[i].CanBeDisable())
				{
					return true;
				}
			}
			return false;
		}

		public bool IsAKeyAvailable()
		{
			for (int i = 0; i < keys.Count; i++)
			{
				if (keys[i].isKeyEnable)
				{
					return true;
				}
			}
			return false;
		}

		public void Dispose()
		{
			foreach (KeyVisual key in keys)
			{
				key.Dispose();
			}
			keys.Clear();
			keys = null;
			keyPrefab = null;
		}
	}
}
